<?PHP
if(isset($_POST['post'])){
	echo '<pre>';
	print_r($_POST);
	print_r($_FILES);
	exit();
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>简单的动态 删除、添加 file标签</title>
</head>
<style type="text/css">
body{
background-color:#F3F8FC;color:#666666
}
#form1 div{
margin:10px;
padding:10px;
border:1px dashed #CCCCCC;
} 
</style>
<script type="text/javascript" >
var file_num=1;
function fnAdd(){
	var p = document.createElement("p");
	p.id = 'p'+(file_num);
	document.getElementById('files').appendChild(p); 
	var f = document.createElement("input");
	f.type="file";
	f.name="file"+file_num;
	p.appendChild(f); 
	var a = document.createElement("a");
	a.href = 'javascript:fnDel('+file_num+')';
	a.appendChild(document.createTextNode("删除"));
	p.appendChild(a); 

	file_num++;
}
function fnDel(id){
	var files = document.getElementById("files");
	var children = files.getElementsByTagName('p');
	for(i=0;i<children.length;i++){ 
		if(children[i].id == ('p'+id)){
			files.removeChild(children[i]);
			break;
		}
	}
}
</script>
<body >
<form id="form1" action="" method="post" enctype="multipart/form-data" >
	<input type="hidden" name="post" value="1" />
	<div>
		<input type="button" value="添加一个 file" onclick="fnAdd()" /> 
	</div>
	<div id="files">
	</div>
	<div>
		<input type="submit" value="提交" />
		<input type="reset" value="试试重置" />
	</div>
</form>
</body>
</html>
